<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>学生选课管理</title>

    <%@ include file="base.jsp" %>

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="./css/x-admin.css" media="all">
    <link rel="stylesheet" href="css/pag.css" media="all">
    <link rel="stylesheet" href="css/query.css" media="all">
</head>

<body>
<div class="x-nav"><span class="layui-breadcrumb"> <a><cite>课程管理</cite></a> <a><cite>选择教师</cite></a> </span> <a
        class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
        href="student/stuTeaController?fun=index" title="刷新"><i class="layui-icon"
                                                                style="line-height:30px">ဂ</i></a></div>
<div class="x-body">
    <div class="tools">
        <span class="x-right" style="line-height:25px">可选教师：<span
                id="count">${allList.size()}</span> 条</span></xblock>
    </div>
    <table class="tablelist">
        <thead>
        <tr>
            </th>
            <th> 课程名称</th>
            <th> 教师名称</th>
            <th> 教师所属学院</th>
            <th> 操作</th>
        </tr>
        </thead>
        <tbody id="x-link">
        <c:forEach var="i" items="${allList}">
            <tr>
                <td>${i.suname}</td>
                <td>${i.tname}</td>
                <td>${i.cname}</td>
                <td class="td-manage">
                    <a
                            title="选择教师"
                            href="javascript:;"
                            onclick="orderTeacher(${i.suid},${i.tid})"
                            style="text-decoration:none">
                        <i class="layui-icon">&#xe642;</i>
                        选择教师
                    </a></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<div class="x-body">
    <div class="tools">
        <ul class="toolbar">
            <li>
                <span onclick="deleteSelect()"><span><img src="images/t03.png"/></span>批量取消选择教师</span>
            </li>
        </ul>
        <span class="x-right" style="line-height:25px">已选教师：<span
                id="count2">${ownList.size()}</span> 条</span></xblock>
    </div>
    <table class="tablelist">
        <thead>
        <tr>
            <th><input onclick="selectAll()" type="checkbox" name="controlAll" style="" id="controlAll">
            </th>
            <th>课程名称</th>
            <th> 教师名称</th>
            <th> 教师所属学院</th>
            <th> 操作</th>
        </tr>
        </thead>
        <tbody id="x-link">
        <c:forEach var="i" items="${ownList}">
            <tr>
                <td><input class="selected" type="checkbox" value="${i.suid},${i.tid}" name="selected"></td>
                <td>${i.suname}</td>
                <td>${i.tname}</td>
                <td>${i.cname}</td>
                <td class="td-manage">
                    <a
                            title="取消选择"
                            href="javascript:;"
                            onclick="deleteTeacher(${i.suid},${i.tid})"
                            style="text-decoration:none">
                        <i class="layui-icon">&#xe642;</i>
                        取消选择
                    </a></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<br/>
<br/>
<br/>
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script src="./js/x-layui.js" charset="utf-8"></script>

<script src="js/jquery2.js" charset="utf-8"></script>
<script src="js/js.js" charset="utf-8"></script>
<script>
    layui.use(['element', 'laypage', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        form = layui.form();//弹出层
    });

</script>
<script>
    $('.tablelist tbody tr:odd').addClass('odd');
</script>
<script>

    //选择教师
    function orderTeacher(suid, tid) {
        $.ajax({
            url: '<%=request.getContextPath()%>/student/stuTeaController',
            data: {
                "fun": 'order',
                "suid": suid,
                "tid": tid
            },
            dataType: 'json',
            success(data) {
                if (data.code <= 0) {
                    layer.alert(data.msg)
                } else {
                    location.href = "<%=request.getContextPath()%>/student/stuTeaController?fun=index";
                }
            }
        })
    }

    //取消选择教师
    function deleteTeacher(suid, tid) {
        layer.confirm(
            '您确定要取消选择该教师？',
            ['确定', '取消'],
            function () {
                $.ajax({
                    url: '<%=request.getContextPath()%>/student/stuTeaController',
                    data: {
                        "fun": 'delete',
                        "suid": suid,
                        "tid": tid
                    },
                    dataType: 'json',
                    success(data) {
                        if (data.code <= 0) {
                            layer.alert(data.msg)
                        } else {
                            location.href = "<%=request.getContextPath()%>/student/stuTeaController?fun=index";
                        }
                    }
                })
            }
        )
    }

    //批量取消选择教师
    function deleteSelect() {
        layer.confirm(
            '您确定取消选择所有选中的教师？',
            ['确定', "取消"],
            function () {
                var ids = [];
                $('.selected:checked').each(function () {
                    ids.push($(this).val())
                })
                $.ajax({
                    url: '<%=request.getContextPath()%>/student/stuTeaController',
                    data: {
                        "ids": ids,
                        "fun": "deleteSelect"
                    },
                    dataType: 'json',
                    success(data) {
                        if (data.code <= 0) {
                            layer.alert(data.msg)
                        } else {
                            location.href = "<%=request.getContextPath()%>/student/stuTeaController?fun=index";
                        }
                    }
                })
            }
        )
    }

</script>
</body>

</html>